import request from '../utils/http'

// 获取订单列表
export function getOrdersList(data) {
  return request({
    url: '/procurement-orders',
    method: 'get',
    params: data
  })
}

//根据供应商id获取它的所有可以采购的物资列表
export function getSupplierMaterials(data) {
  return request({
    url: `/procurement-orders/supplier_goods`,
    method: 'get',
    params: data
  })
}

//创建采购订单
export function createOrder(data) {
  return request({
    url: '/procurement-orders',
    method: 'post',
    data
  })
}

//保存修改的订单
export function updateOrder(orderID,data) {
  return request({
    url: '/procurement-orders/'+orderID,
    method: 'put',
    data
  })
}

//修改订单状态：/procurement-orders/39/status
export function updateOrderStatus(orderID,data) {
  return request({
    url: '/procurement-orders/status/'+orderID,
    method: 'put',
    data
  })
}

//新增一条食材信息
/*
* @param order_id:订单id
* @param data:
* {
*   goodsId: 物资id,
*   goodsCount: 采购数量,
*   notes: 备注
* }
* @return: 新增的食材信息
* */
export function createMaterial(order_id,data) {
  return request({
    url: `/procurement-orders/orders/${order_id}/items`,
    method: 'post',
    data
  })
}

//删除采购单中的一条食材信息
/*
* @params order_id 订单id
* @params goods_id 商品id
* @return: 删除的食材信息
* */
export function deleteMaterial(order_id,goods_id) {
  return request({
    url: `/procurement-orders/delete_items/${order_id}/${goods_id}`,
    method: 'delete'
  })
}

//根据订单id 删除该订单及其所有食材信息
/*
* @desc 删除采购单
* @params order_id 订单id
* */
export function deleteOrder(order_id) {
  return request({
    url: `/procurement-orders/orders/${order_id}`,
    method: 'delete'
  })
}

/*
* @desc 处理采购订单时更新食材表信息
* @params goodsID      //食材id
* @params data  Object      //数据
* inPrice      //出库价格
* outPrice     //采购价格
* safetyStock  //安全库存
* */
export function updateMaterials(goodsID,data) {
  return request({
    url: `/procurement-orders/goods/${goodsID}`,
    method: 'put',
    data
  })
}